package com.example.kai.uno.uno;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;

import com.example.kai.uno.R;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;

public class Desk {
	public static int winId = -1;
	Bitmap pokeImage;
	Bitmap tishi;
	Bitmap buyao;
	Bitmap chupai;
	int dir;
	public static int[] personScore = new int[3];
	LInedQueue team;
	int times1;
	int times2;
	boolean out;
	private int[][] rolePos = { { 60, 310 }, { 63, 19 }, { 396, 19 }, };
	int num1;
	int num2;
	int num0;
	public static Person[] persons = new Person[3];// ???????
	public static int[] deskPokes = new int[110];// ????????
	public static int currentScore = 3;// ???????
	public static int boss = 0;// ????
	/**
	 * -2:发牌<br>
	 * -1:随机地主<br>
	 * 0:游戏中 <br>
	 * 1:游戏结束，重新来，活退出<br>
	 */
	private int op = -1;// ???????????
	public static int currentPerson = 0;// ???????????
	public static int currentCircle = 0;// ???????
	public static Card currentCard = null;// ??????????

	public int[][] personPokes = new int[3][109];

	// gaming
	private int timeLimite = 310;
	private int[][] timeLimitePos = { { 130, 205 }, { 118, 76 }, { 327, 76 } };
	private int opPosX = 240;
	private int opPosY = 200;

	DDZ ddz;

	public Desk(DDZ ddz) {
		this.ddz = ddz;
		pokeImage = BitmapFactory.decodeResource(ddz.getResources(),
				R.drawable.uno);
		tishi = BitmapFactory
				.decodeResource(ddz.getResources(), R.drawable.cp0);
		buyao = BitmapFactory
				.decodeResource(ddz.getResources(), R.drawable.cp1);
		chupai = BitmapFactory.decodeResource(ddz.getResources(),
				R.drawable.cp2);
		// init();
		dir=0;
		team=new LInedQueue();
		times1=0;
		times2=0;
		num0=0;
		num1=0;
		num2=0;
		out=true;
	}

	private  void shoupaiadd(int currentPerson,int time){

		if (currentPerson==0){
			for (int i =0;i<time;i++){
			num0++;

			}

		}
		if (currentPerson==1){
			for (int i =0;i<time;i++){
				num1++;

			}
		}
		if (currentPerson==2){
			for (int i =0;i<time;i++){
				num2++;

			}
		}
	}
	private  void shoupaidelete(int currentPerson){

		if (currentPerson==0){
			num0--;

		}
		if (currentPerson==1){
			num1--;
		}
		if (currentPerson==2){
			num2--;
		}
	}
	private int returnshoupai(int currentPerson){
		int result=-1;
		if (currentPerson==0){
			result= num0;
		}
		if (currentPerson==1){
			result= num1;
		}
		if (currentPerson==2){
			result= num2;
		}
		return result;
	}
	public void gameLogic() {
		switch (op) {
		case -2:
			break;
		case -1:
			init();
			op = 0;
			break;
		case 0:
			gaming();
			break;
		case 1:
			break;
		case 2:
			break;
		}
	}

	// 存储当前一句的胜负得分信息
	int rs[] = new int[3];

	private  void Dir(int dir){
		switch (dir){
			case 0:{
				nextPerson();
			}
			case 1:{
				lastPerson();
			}
		}
	}
	private boolean findadd4(int[] temp){
		boolean result = false;
		for (int i =0;i<temp.length;i++){
			if (temp[i]==52){
				result=true;
				break;
			}
		}
		return result;
	}
	private boolean findfunction(int[] temp,int function){
		boolean result = false;
		for (int i =0;i<temp.length;i++){
			if (temp[i]==function){
				result=true;
				break;
			}
		}
		return result;
	}
	private boolean findadd2(int[] temp){
		boolean result = false;
		for (int i =0;i<temp.length;i++){
			if (temp[i]==12||temp[i]==25||temp[i]==38||temp[i]==51){
				result=true;
				break;
			}
		}
		return result;
	}


	private void gaming() {

		for (int k = 0; k < 3; k++) {

			if (persons[k].pokes.length == 0||team.size()==0) {//应当还有当牌桌的牌为0时结束
				op = 1;
				winId = k;
				}

		}

		// 游戏没有结束，继续。
		// 如果本家ID是NPC，则执行语句中的操作
		if (currentPerson == 1 || currentPerson == 2) {

			if (timeLimite <= 300) {

				//System.out.println(returnshoupai(currentPerson));
				System.out.println(num0+" "+num1+" "+num2);
				if (currentCard.poke == 53) {///////////////////////////////
					System.out.println("+4");
					//给当前玩家加四张牌
//					if (findadd4(personPokes[currentPerson])){
//						System.out.println("+4chupai");
//						Card tempcard = persons[currentPerson].chupaiAI(currentCard);
//						currentCircle++;
//						currentCard = tempcard;
//						times1++;
//						shoupaidelete(currentPerson);
//						out=false;
//						nextPerson();
//
////						Dir(dir);
//					}
//					else {
						//加四张牌
					//	for (int a =0;a<times1;a++) {
						System.out.println("+4meichupai");
							int temp[] = personPokes[currentPerson];

							personPokes[currentPerson] = new int[returnshoupai(currentPerson) + 4];
							for (int i = 0; i < returnshoupai(currentPerson); i++) {
								personPokes[currentPerson][i] = temp[i];
							}
							for (int i = 0; i < 4; i++) {
								personPokes[currentPerson][returnshoupai(currentPerson)] = (int) team.dequeue();
								shoupaiadd(currentPerson, 1);
							}
					persons[currentPerson].pokes=personPokes[currentPerson];
							currentCircle++;
					//		}
						times1=0;
						nextPerson();
						//nextPerson();
						out=false;
						//Dir(dir);
					}
				//}


//####################
				if (currentCard.poke == 11 || currentCard.poke == 24 || currentCard.poke == 37 || currentCard.poke == 50) {
					System.out.println("+2");
					//给当前玩家加两张牌
//					if (findadd2(personPokes[currentPerson])){
//						Card tempcard = persons[currentPerson].chupaiAI(currentCard);
//						currentCircle++;
//						currentCard = tempcard;
//						times2++;
//						shoupaidelete(currentPerson);
//						out=false;
//						nextPerson();
////						Dir(dir);
//					}else {
						add2(1);
						shoupaiadd(currentPerson,times2*2);
						times2=0;
					persons[currentPerson].pokes=personPokes[currentPerson];
					}
				//}
				//####################
				Card temp1=currentCard;
				if (out){
					System.out.println("aichupai");
				Card tempcard = persons[currentPerson].chupaiAI(currentCard);
				if (tempcard != null) {
					shoupaidelete(currentPerson);
					currentCircle++;
					currentCard = tempcard;

					if (currentCard.poke==53){
						times1++;
					}
					if (currentCard.poke == 11 || currentCard.poke == 24 || currentCard.poke == 37 || currentCard.poke == 50) {
						times2++;
					}
					//Dir(dir);
				///////////////?#####################
					if ( currentCard.poke == PokeType.alladd1 || currentCard.poke == PokeType.alladd2 ){
						System.out.println("+1/+2");
						if (currentCard.poke == PokeType.alladd1) {
							if (currentPerson == 1) {
								//给2,0加1张牌
								int temp[]=personPokes[0];
								System.out.println(Arrays.toString(temp));
								System.out.println(returnshoupai(0));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[0]=new int[returnshoupai(0)+1];
								for (int i =0;i<returnshoupai(0);i++){
									personPokes[0][i]=temp[i];
								}
								for (int i =0;i<1;i++){
									personPokes[0][returnshoupai(0)]= (int) team.dequeue();
									shoupaiadd(0,1);}
								currentCircle++;

								///////////#############??????????????
								int temp2[]=personPokes[2];
								System.out.println(Arrays.toString(temp2));
								System.out.println(returnshoupai(2));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[2]=new int[returnshoupai(2)+1];
								for (int i =0;i<returnshoupai(2);i++){
									personPokes[2][i]=temp2[i];
								}
								for (int i =0;i<1;i++){
									personPokes[2][returnshoupai(2)]= (int) team.dequeue();
									shoupaiadd(2,1);}
								currentCircle++;
								}
							if (currentPerson == 2) {
								//0,1加1张牌

								int temp[]=personPokes[0];
								System.out.println(Arrays.toString(temp));
								System.out.println(returnshoupai(0));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[0]=new int[returnshoupai(0)+1];
								for (int i =0;i<returnshoupai(0);i++){
									personPokes[0][i]=temp[i];
								}
								for (int i =0;i<1;i++){
									personPokes[0][returnshoupai(0)]= (int) team.dequeue();
									shoupaiadd(0,1);}
								currentCircle++;


								/////////////////??#################
								int temp2[]=personPokes[1];
								System.out.println(Arrays.toString(temp2));
								System.out.println(returnshoupai(1));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[1]=new int[returnshoupai(1)+1];
								for (int i =0;i<returnshoupai(1);i++){
									personPokes[1][i]=temp2[i];
								}
								for (int i =0;i<1;i++){
									personPokes[1][returnshoupai(1)]= (int) team.dequeue();
									shoupaiadd(1,1);}
								currentCircle++;



							}
						}
						if (currentCard.poke == PokeType.alladd2) {
							if (currentPerson == 1) {
								//给2,0加两张牌
								int temp[]=personPokes[0];
								System.out.println(Arrays.toString(temp));
								System.out.println(returnshoupai(0));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[0]=new int[returnshoupai(0)+2];
								for (int i =0;i<returnshoupai(0);i++){
									personPokes[0][i]=temp[i];
								}
								for (int i =0;i<2;i++){
									personPokes[0][returnshoupai(0)]= (int) team.dequeue();
									shoupaiadd(0,1);}
								currentCircle++;


								///////////#############??????????????
								int temp2[]=personPokes[2];
								System.out.println(Arrays.toString(temp2));
								System.out.println(returnshoupai(2));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[2]=new int[returnshoupai(2)+2];
								for (int i =0;i<returnshoupai(2);i++){
									personPokes[2][i]=temp2[i];
								}
								for (int i =0;i<2;i++){
									personPokes[2][returnshoupai(2)]= (int) team.dequeue();
									shoupaiadd(2,1);}
								currentCircle++;



							}
							if (currentPerson == 2) {
								//0,1加两张牌

								int temp[]=personPokes[0];
								System.out.println(Arrays.toString(temp));
								System.out.println(returnshoupai(0));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[0]=new int[returnshoupai(0)+2];
								for (int i =0;i<returnshoupai(0);i++){
									personPokes[0][i]=temp[i];
								}
								for (int i =0;i<2;i++){
									personPokes[0][returnshoupai(0)]= (int) team.dequeue();
									shoupaiadd(0,1);}
								currentCircle++;


								/////////////////??#################
								int temp2[]=personPokes[1];
								System.out.println(Arrays.toString(temp2));
								System.out.println(returnshoupai(1));
								System.out.println(num0+" "+num1+" "+num2);
								personPokes[1]=new int[returnshoupai(1)+2];
								for (int i =0;i<returnshoupai(1);i++){
									personPokes[1][i]=temp2[i];
								}
								for (int i =0;i<2;i++){
									personPokes[1][returnshoupai(1)]= (int) team.dequeue();
									shoupaiadd(1,1);}
								currentCircle++;

							}
						}
					}
					nextPerson();
/////////////////??#################
//					if (currentCard.poke == PokeType.rveer || currentCard.poke == PokeType.gveer || currentCard.poke == PokeType.yveer || currentCard.poke == PokeType.bveer) {
//						if (dir == 0) {
//							dir = 1;
//						} else if (dir == 1) {
//							dir = 0;
//						}
//					}
//					Dir(dir);
					///////////??#################
					if (currentCard.poke==PokeType.alladd4||currentCard.poke==PokeType.alladd2||currentCard.poke==PokeType.alladd1||currentCard.poke==PokeType.allchange){
						//请选择四个颜色中的一个
						Random random =new Random();
						int temp=random.nextInt(4);
						currentCard=persons[currentPerson].colorselect(temp);
						if (temp==0){//红
							//气泡显示选择红色
							System.out.println("red");
						}
						if (temp==1){//黄
							//气泡显示选择黄色
							System.out.println("yellow");
						}
						if (temp==2){//蓝
							//气泡显示选择蓝色
							System.out.println("blue");
						}
						if (temp==3){//绿
							//气泡显示选择绿色
							System.out.println("green");
						}
					}
					///////////??#################
					if (currentCard.poke == PokeType.bskip || currentCard.poke == PokeType.rskip || currentCard.poke == PokeType.yskip || currentCard.poke == PokeType.gskip)
				{
					System.out.println("stop");
				nextPerson();
				nextPerson();
//					Dir(dir);
//					Dir(dir);
				}

				}
				else {
					currentCard=temp1;
					buyao();//出不去牌+2

				}

				}
				out=true;
				System.out.println(Arrays.toString(personPokes[0]));
				System.out.println(Arrays.toString(personPokes[1]));
				System.out.println(Arrays.toString(personPokes[2]));
				System.out.println(currentCard.poke);
//				if (currentPerson==0);{
//				persons[0] = new Person(personPokes[0], 234, 96, PokeType.dirH, 0,
//						this, ddz);}
//						if (currentPerson==1){
//				persons[1] = new Person(personPokes[1], 54, 28, PokeType.dirV, 1, this,
//						ddz);}
//						if (currentPerson==2){
//				persons[2] = new Person(personPokes[2], 54, 417, PokeType.dirV, 2,
//						this, ddz);}
			}
		}

		timeLimite -= 2;
		}





	public void init() {
		deskPokes = new int[110];
		personPokes = new int[3][5];
		num2=0;
		num1=0;
		num0=0;
		times1=0;
		times2=0;
		dir=0;
		winId = -1;
		currentScore = 3;
		currentCard = null;
		currentCircle = 0;
		currentPerson = 0;

//		for (int i = 0; i < 56; i++) {
//
//			deskPokes[i] = i;
//		}
		for (int i = 0; i < 52; i++) {

			deskPokes[i] = i;
		}
		deskPokes[52]=34;
		deskPokes[53]=44;
		deskPokes[54]=23;
		deskPokes[55]=22;

		int a1=1;
		for (int i =56;i<68;i++){
			deskPokes[i]=a1;
			a1++;
		}
		int a2=14;
		for (int i =68;i<80;i++){
			deskPokes[i]=a2;
			a2++;
		}
		int a3=27;
		for (int i =80;i<92;i++){
			deskPokes[i]=a3;
			a3++;
		}
		int a4=40;
		for (int i =92;i<104;i++){
			deskPokes[i]=a4;
			a4++;
		}
		for (int i =104;i<107;i++){
			//deskPokes[i]=52;
			deskPokes[i]=22;
			/////////////////////////////////////
		}
		for (int i =107;i<110;i++){
			//deskPokes[i]=53;
			deskPokes[i]=35;
			/////////////////////////////////////
		}
		for (int i =0;i<110;i++){
			if (deskPokes[i]==25||deskPokes[i]==36||deskPokes[i]==38){
				deskPokes[i]=3;
			}
		}
		for (int i =0;i<110;i++){
			if (deskPokes[i]==10||deskPokes[i]==12||deskPokes[i]==23){
				deskPokes[i]=35;
			}
		}
		for (int i =0;i<110;i++){
			if (deskPokes[i]==25||deskPokes[i]==36||deskPokes[i]==38){
				deskPokes[i]=3;
			}
		}
		for (int i =0;i<110;i++){
			if (deskPokes[i]==49||deskPokes[i]==51){
				deskPokes[i]=4;
			}
		}
		Poke.shuffle(deskPokes);
		fenpai(deskPokes);
		//randDZ();
		Poke.sort(personPokes[0]);
		Poke.sort(personPokes[1]);
		Poke.sort(personPokes[2]);
		persons[0] = new Person(personPokes[0], 234, 96, PokeType.dirH, 0,
				this, ddz);
		persons[1] = new Person(personPokes[1], 54, 28, PokeType.dirV, 1, this,
				ddz);
		persons[2] = new Person(personPokes[2], 54, 417, PokeType.dirV, 2,
				this, ddz);
		persons[0].setPosition(persons[1], persons[2]);
		persons[1].setPosition(persons[2], persons[0]);
		persons[2].setPosition(persons[0], persons[1]);


		for (int i = 0; i < 3; i++) {
			StringBuffer sb = new StringBuffer();
			sb.append("chushipai---" + i + ":");
			for (int j = 0; j < personPokes[i].length; j++) {
				sb.append(personPokes[i][j] + ",");
			}
			System.out.println(sb.toString());
		}
	}



	private void add2(int num){
		for (int a =0;a<num;a++){
		int temp[]=personPokes[currentPerson];
		System.out.println(Arrays.toString(temp));
		System.out.println(returnshoupai(currentPerson));
		System.out.println(num0+" "+num1+" "+num2);
		personPokes[currentPerson]=new int[returnshoupai(currentPerson)+2];
		for (int i =0;i<returnshoupai(currentPerson);i++){
			personPokes[currentPerson][i]=temp[i];
		}
		for (int i =0;i<2;i++){
			personPokes[currentPerson][returnshoupai(currentPerson)]= (int) team.dequeue();
			shoupaiadd(currentPerson,1);}
		}

		currentCircle++;

	}

	public void fenpai(int[] pokes) {

		for (int i =0;i<109;i++){
			team.enqueue(pokes[i]);
		}
		for (int i =0;i<5;i++){
			personPokes[0][i]= (int) team.dequeue();

			shoupaiadd(0,1);
		}
		for (int i =0;i<5;i++){
			personPokes[1][i]= (int) team.dequeue();

			shoupaiadd(1,1);
		}
		for (int i=0;i<5;i++){
			personPokes[2][i]= (int) team.dequeue();

			shoupaiadd(2,1);
		}
	}


	public void paint(Canvas canvas) {

		switch (op) {
		case -2:
			break;
		case -1:
			break;
		case 0:
			paintGaming(canvas);
			break;
		case 1:
			paintResult(canvas);
			break;
		case 2:
			break;
		}

	}

	private void paintResult(Canvas canvas) {
		Paint paint = new Paint();
		paint.setColor(Color.WHITE);
		paint.setTextSize(20);

		canvas.drawText("", 110, 66, paint);
		for (int i = 0; i < 3; i++) {
			canvas.drawText(i + "" + rs[i] + "" + personScore[i],
					110, 96 + i * 30, paint);
		}

	}

	private void paintGaming(Canvas canvas) {
		persons[0].paint(canvas);
		persons[1].paint(canvas);
		persons[2].paint(canvas);

		paintRoleAndScore(canvas);
		if (currentPerson == 0) {
			Rect src = new Rect();
			Rect dst = new Rect();
			src.set(0, 0, chupai.getWidth(), chupai.getHeight());
			dst.set(opPosX, opPosY, opPosX + chupai.getWidth(), opPosY
					+ chupai.getHeight());
			canvas.drawBitmap(chupai, src, dst, null);
			if (currentCircle != 0) {
				src.set(0, 0, tishi.getWidth(), tishi.getHeight());
				dst.set(opPosX + 40, opPosY, opPosX + tishi.getWidth() + 40,
						opPosY + tishi.getHeight());
				canvas.drawBitmap(tishi, src, dst, null);
				src.set(0, 0, buyao.getWidth(), buyao.getHeight());
				dst.set(opPosX - 40, opPosY, opPosX + buyao.getWidth() - 40,
						opPosY + buyao.getHeight());
				canvas.drawBitmap(buyao, src, dst, null);
			}
		}

		if (persons[0].card != null) {
			persons[0].card.paint(canvas, 130, 140, PokeType.dirH);
		}
		if (persons[1].card != null) {
			persons[1].card.paint(canvas, 73, 56, PokeType.dirV);
		}
		if (persons[2].card != null) {
			persons[2].card.paint(canvas, 365, 56, PokeType.dirV);
		}

		paintTimeLimite(canvas);
		Paint paint = new Paint();
		paint.setTextAlign(Align.LEFT);
		paint.setStyle(Style.FILL_AND_STROKE);
		paint.setTextSize(14);
		canvas.drawText("" + currentScore, 165, 308, paint);

	}

	private void paintTimeLimite(Canvas canvas) {
		Paint paint = new Paint();
		paint.setColor(Color.BLUE);
		paint.setTextSize(16);
		for (int i = 0; i < 3; i++) {
			if (i == currentPerson) {
				canvas.drawText("" + (timeLimite / 10), timeLimitePos[i][0],
						timeLimitePos[i][1], paint);
			}
		}
	}

	private void paintRoleAndScore(Canvas canvas) {
		Paint paint = new Paint();
		for (int i = 0; i < 3; i++) {
			if (boss == i) {
				paint.setColor(Color.RED);
				canvas.drawText("老王"  , rolePos[i][0],
						rolePos[i][1], paint);
			} else {
				paint.setColor(Color.WHITE);
				canvas.drawText("老李"  , rolePos[i][0],
						rolePos[i][1], paint);
			}
		}
	}



	public void onTuch(View v, MotionEvent event) {
		for (int i = 0; i < persons.length; i++) {
			StringBuffer sb = new StringBuffer();
			sb.append(i + " : ");
			for (int j = 0; j < persons[i].pokes.length; j++) {
				sb.append(persons[i].pokes[j]
						+ (persons[i].pokes[j] >= 10 ? "" : " ") + ",");
			}
			System.out.println(sb.toString());
		}

		if (op == 1) {
			System.out.println("ddz.handler:" + ddz.handler);
			init();
			op = 0;

		}
		if (currentPerson != 0) {
			return;
		}
		int x = (int) event.getX();
		int y = (int) event.getY();

		if (Poke.inRect(x, y, opPosX, opPosY, 38, 23)) {
			System.out.println("chupai");
					Card temp1=currentCard;
				if (currentCard!=null){
					if (currentCard.poke==PokeType.alladd4){
                       // for (int a =0;a<times1;a++){
                            int temp[]=personPokes[0];
                            System.out.println(Arrays.toString(temp));
                            System.out.println(returnshoupai(0));
                            System.out.println(num0+" "+num1+" "+num2);
                            personPokes[0]=new int[returnshoupai(0)+4];
                            for (int i =0;i<returnshoupai(0);i++){
                                personPokes[0][i]=temp[i];
                            }
                            for (int i =0;i<4;i++){
                                personPokes[0][returnshoupai(0)]= (int) team.dequeue();
                                shoupaiadd(0,1);}
                      //  }
                        times1=0;
                        out=false;
                        nextPerson();
					}
					if (currentCard.poke==PokeType.radd2||currentCard.poke==PokeType.yadd2||currentCard.poke==PokeType.badd2||currentCard.poke==PokeType.gadd2){
                       // for (int a =0;a<times2;a++){
                            int temp[]=personPokes[0];
                            System.out.println(Arrays.toString(temp));
                            System.out.println(returnshoupai(0));
                            System.out.println(num0+" "+num1+" "+num2);
                            personPokes[0]=new int[returnshoupai(0)+2];
                            for (int i =0;i<returnshoupai(0);i++){
                                personPokes[0][i]=temp[i];
                            }
                            for (int i =0;i<2;i++){
                                personPokes[0][returnshoupai(0)]= (int) team.dequeue();
                                shoupaiadd(0,1);}
                      //  }
                        times2=0;
                    }
				}

				Card card = persons[0].chupai(currentCard);
				shoupaidelete(currentPerson);

				if (out) {
					if (card != null) {
						currentCard = card;
						currentCircle++;
						//Dir(dir);
						nextPerson();

						if (currentCard.poke==52||currentCard.poke==53||currentCard.poke==54||currentCard.poke==55){
							//选择

						}
					}
//					currentCard=temp1;
				}

		out=true;

		}
		if (currentCircle != 0) {
			if (Poke.inRect(x, y, opPosX - 40, opPosY, 38, 23)) {
				System.out.println("buyao");
				//buyao();

			}
		}
		if (Poke.inRect(x, y, opPosX + 40, opPosY, 38, 23)) {
			System.out.println("tishi");
			tishi();
		}
		persons[0].onTuch(v, event);
	}

	private void tishi() {

	}

	private void buyao() {
		int temp[]=personPokes[currentPerson];
//		System.out.println(Arrays.toString(temp));
//		System.out.println(returnshoupai(currentPerson));
//		System.out.println(num0+" "+num1+" "+num2);
		personPokes[currentPerson]=new int[returnshoupai(currentPerson)+2];
		for (int i =0;i<returnshoupai(currentPerson);i++){
			personPokes[currentPerson][i]=temp[i];
		}
		for (int i =0;i<2;i++){
		personPokes[currentPerson][returnshoupai(currentPerson)]= (int) team.dequeue();
		shoupaiadd(currentPerson,1);}
		currentCircle++;
		persons[currentPerson].pokes=personPokes[currentPerson];
//		persons[0] = new Person(personPokes[0], 234, 96, PokeType.dirH, 0,
//				this, ddz);
//		persons[1] = new Person(personPokes[1], 54, 28, PokeType.dirV, 1, this,
//				ddz);
//		persons[2] = new Person(personPokes[2], 54, 417, PokeType.dirV, 2,
//				this, ddz);

		//Dir(dir);
		nextPerson();


	}


	private void nextPerson() {
		switch (currentPerson) {
		case 0:
			currentPerson = 2;
			break;
		case 1:
			currentPerson = 0;
			break;
		case 2:
			currentPerson = 1;
			break;
		}
		timeLimite = 310;
	}
	private void lastPerson(){
		switch (currentPerson) {
			case 0:
				currentPerson = 1;
				break;
			case 1:
				currentPerson = 2;
				break;
			case 2:
				currentPerson = 0;
				break;
		}
		timeLimite = 310;
	}
}
